package com.lancoo.answer.ui.child.lookReview;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lancoo.answer.R;
import com.lancoo.answer.model.AnswerConstant;
import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.Type;
import com.lancoo.answer.widget.combinationView.AnswerAnalysisView;
import com.lancoo.answer.widget.combinationView.ReadingMatchQueseBodyView;

import java.util.List;


/**
 * Created by pengmi on 2021/12/1 20:53
 * Description:阅读匹配小题查看评阅fragment
 */
public class ChildReadMatchLookReviewFragment extends Fragment {

    private Child child;
    private View convertView;
    private static final String TAG = "ReadingQueseMatchFragme";
    private ReadingMatchQueseBodyView queseBodyView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        convertView = inflater.inflate(R.layout.ev_temp_fragment_reading_match_answer_quese, container, false);
        return convertView;
    }

    public static Fragment loadChildFragment(int kindIndex, int queseIndex, int smallQueseIndex) {
        ChildReadMatchLookReviewFragment queseFragment = new ChildReadMatchLookReviewFragment();
        Bundle mBundle = new Bundle();
        mBundle.putInt(AnswerConstant.KEY_TYPEINDEX, kindIndex);
        mBundle.putInt(AnswerConstant.KEY_QUESINDEX, queseIndex);
        mBundle.putInt(AnswerConstant.KEY_CHILDINDEX, smallQueseIndex);
        queseFragment.setArguments(mBundle);
        return queseFragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        if (getArguments() == null) {
            return;
        }
        int kindIndex = getArguments().getInt(AnswerConstant.KEY_TYPEINDEX);
        int queseIndex = getArguments().getInt(AnswerConstant.KEY_QUESINDEX);
        int smallQueseIndex = getArguments().getInt(AnswerConstant.KEY_CHILDINDEX);
        Log.e(TAG, "initView，kindIndex：" + kindIndex + ",queseIndex:" + queseIndex + ",smallQueseIndex:" + smallQueseIndex);
        List<Type> kindBeanListk = ConstantBean.Companion.getConstantExamBean().getTypeList();
        child = kindBeanListk.get(kindIndex).getQuesList().get(queseIndex).getChildList().get(smallQueseIndex);
        queseBodyView = view.findViewById(R.id.quese_body_view);
        queseBodyView.setTrainType(2);
        queseBodyView.initData(child);
        AnswerAnalysisView answerAnalysisView = view.findViewById(R.id.answer_analysis_view);
        answerAnalysisView.setAnalysis(child.getChildAnalysis());
    }

    @Override
    public void onPause() {
        super.onPause();
        if (queseBodyView != null) {
            queseBodyView.pause();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (queseBodyView != null) {
            queseBodyView.release();
        }
    }

    public void adjustFontSize(){
        if(convertView==null){
            return;
        }
        ReadingMatchQueseBodyView queseBodyView = convertView.findViewById(R.id.quese_body_view);
        queseBodyView.adjustFontSize();
        AnswerAnalysisView answerAnalysisView=convertView.findViewById(R.id.answer_analysis_view);
        answerAnalysisView.adjustFontSize();
    }

}
